package com.platform.novel.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.annotation.IgnoreAuth;
import com.platform.entity.CategoryEntity;
import com.platform.entity.GoodsEntity;
import com.platform.service.CategoryService;
import com.platform.util.ApiBaseAction;
import com.platform.utils.R;

import io.swagger.annotations.Api;

@Api(tags = "novel_category")
@RestController
@RequestMapping("/apin/category")
public class ApiCategoryController extends ApiBaseAction{
    @Autowired
    private CategoryService categoryService;
    /**
     * 查看列表
     */
    @IgnoreAuth
    @RequestMapping("/list/{level}")
    public R category(
    		@PathVariable("level") String level,
    		@RequestParam Map<String, Object> map) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("level", level);
        params.put("isShow", 1);
        params.put("sidx", "sort_order");
        params.put("order", "desc");
        
        if(map.get("parentId") != null) {
            params.put("parentId",map.get("parentId"));
        }
        if(map.get("type") != null) {
        	params.put("type",map.get("type"));
        }
        if(map.get("order") != null) {
            params.put("order", map.get("order"));
        }
        if(map.get("offset") != null) {
            params.put("offset", Integer.valueOf(map.get("offset").toString()));
        }else {
            params.put("offset", 0);
        }
        params.put("limit", 100);

//      if(map.get("limit") != null) {
//          params.put("limit", Integer.valueOf(map.get("limit").toString()));
//      }else {
//          params.put("limit", 6);
//      }
        List<CategoryEntity> categoryList = categoryService.queryList(params);
        return R.ok().put("categoryList", categoryList);
    }
    
    /**
     * 首页展示
     */
    @IgnoreAuth
    @RequestMapping("/home")
    public R homeList(
    		@RequestParam Map<String, Object> map) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("level", "L2");
        params.put("isShow", 1);
        params.put("showIndex", 1);
        params.put("type", 2);
        params.put("sidx", "show_index");
        params.put("order", "desc");
        
        if(map.get("offset") != null) {
            params.put("offset", Integer.valueOf(map.get("offset").toString()));
        }else {
            params.put("offset", 0);
        }
        if(map.get("limit") != null) {
            params.put("limit", Integer.valueOf(map.get("limit").toString()));
        }else {
            params.put("limit", 6);
        }
        List<CategoryEntity> categoryList = categoryService.queryList(params);
        return R.ok().put("categoryList", categoryList);
    }    
}
